package com.example.springmvcdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
//import org.apache.commons.fileupload.disk.DiskFileItemFactory;


@SpringBootApplication
//@EnableAutoConfiguration(exclude = { MultipartAutoConfiguration.class })
public class SpringmvcdemoApplication {

    /*@Bean(name = "multipartResolver")
    public MultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setDefaultEncoding("UTF-8");
        resolver.setResolveLazily(true);// resolveLazily属性启用是为了推迟文件解析，以在在UploadAction中捕获文件大小异常
        resolver.setMaxInMemorySize(40960);
        resolver.setMaxUploadSize(5*1024 *1024*1024);// &#x4e0a;&#x4f20;&#x6587;&#x4ef6;&#x5927;&#x5c0f; 5G
        return resolver;
    }*/

    public static void main(String[] args) {
        SpringApplication.run(SpringmvcdemoApplication.class, args);
        /*ApplicationContext context=new AnnotationConfigApplicationContext(SpringmvcdemoApplication.class);
        CommonsMultipartResolver commonsMultipartResolver = context.getBean("commonsMultipartResolver", CommonsMultipartResolver.class);
        System.out.println(commonsMultipartResolver);*/
    }

    // 显示声明CommonsMultipartResolver为mutipartResolver
    @Bean(name = "multipartResolver")
    public MultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setDefaultEncoding("UTF-8");
        resolver.setResolveLazily(true);// resolveLazily属性启用是为了推迟文件解析，以在在UploadAction中捕获文件大小异常
        resolver.setMaxInMemorySize(40960);
        resolver.setMaxUploadSize(5 * 1024 * 1024 * 1024);// 上传文件大小 5G
        return resolver;
    }

}
